//package com.baixun.gassystem.evs;
//
//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.nio.charset.StandardCharsets;
//import java.security.InvalidKeyException;
//import java.security.NoSuchAlgorithmException;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Map.Entry;
//import javax.crypto.Mac;
//import javax.crypto.spec.SecretKeySpec;
//
//import com.baixun.gascommon.config.ApiConfig;
//import org.apache.commons.codec.binary.Hex;
//
//public class ClientAuthUtil {
//
//    /**
//     * 生成鉴权头参数
//     * @param accessKey 填写您的Access Key
//     * @param secretKey 填写您的Secret Key
//     * @param uri 填写请求的URI
//     * @return 返回header鉴权参数
//     */
//    public static Map<String, String> buildAuthHeaderParams(String accessKey, String secretKey, String uri) {
//        accessKey= "ekpqcprab49rhfngp7m8";
//                secretKey="ekpqywgm10u8api1dh1d";
//        Map<String, String> params = new HashMap<>();
//        // 鉴权过期时间，单位毫秒，请根据实际进行修改
//        String expire = String.valueOf(System.currentTimeMillis() + 600000);
//        String input = String.format("%s;%s;%s;%s", accessKey, secretKey, expire, uri);
//
//        SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
//        String authToken;
//        try {
//            Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());
//            mac.init(secretKeySpec);
//            byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
//            mac.update(inputBytes, 0, inputBytes.length);
//            authToken = new String(Hex.encodeHex(mac.doFinal()));
//        } catch (NoSuchAlgorithmException | InvalidKeyException ex) {
//            throw new IllegalArgumentException(ex);
//        }
//
//        // key: header key   val: header value
//        params.put("x-bce-evs-auth-user", accessKey);
//        params.put("x-bce-evs-auth-expire-date", expire);
//        params.put("x-bce-evs-auth-token", authToken);
//        System.out.println("header params: " + params);
//        return params;
//    }
//
//    /**
//     * 接口请求示例
//     * 基于 getParamsWithNodeAuth 方法生成鉴权参数
//     */
//    public static void main(String[] args) throws Exception {
//        int pointId=200010712;
//        // 请填写实际的 accessKey 、 secretKey 和需要请求的 uri
////        Map<String, String> headerParams = buildAuthHeaderParams("accessKey", "secretKey",
////                "/api/v2/points/"+pointID+"/signed_url");
//
//        Map<String, String> headerParams = buildAuthHeaderParams("accessKey", "secretKey", "/api/v2/ai/apps/points/"+pointId+"/abilities");
//
//        String url = ApiConfig.DOMAIN + "/api/v2/ai/apps/points/" + pointId + "/abilities";
//
//        // 请求地址 + 请求路径， 请根据实际请求地址进行修改
////        String url = "https://evsretail.bce.baidu.com/api/v2/points/"+pointID+"/signed_url?protocol=rtmp";
//
//        URL obj = new URL(url);
//        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//
//        // optional default is GET
//        con.setRequestMethod("GET");
//
//        // 添加请求头
//        for (Entry<String, String> headerParamEntry : headerParams.entrySet()) {
//            con.setRequestProperty(headerParamEntry.getKey(), headerParamEntry.getValue());
//        }
//
//        int responseCode = con.getResponseCode();
//        System.out.println("\nSending 'GET' request to URL : " + url);
//        System.out.println("Response Code : " + responseCode);
//
//        BufferedReader in = new BufferedReader(
//                new InputStreamReader(con.getInputStream()));
//        String inputLine;
//        StringBuffer response = new StringBuffer();
//        while ((inputLine = in.readLine()) != null) {
//            response.append(inputLine);
//        }
//        in.close();
//
//        //print result
//        System.out.println(response.toString());
//    }
//}
//
